<template>
  <div class="app-container">
    <div class="filter-container">
            <el-input v-model="param.supplierName" placeholder="请输入供应商名称" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter"/>
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">搜索</el-button>
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="reset">重置</el-button>
      <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="handleSaveData({})">添加</el-button>
      <el-button v-waves class="filter-item" type="danger" icon="el-icon-delete" @click="tableHandleBatchDelete">批量删除</el-button>
    </div>
    <el-table v-loading="listLoading" :data="list" border fit highlight-current-row style="width: 100%;" @selection-change="handleSelectionChange">
      <el-table-column align="center" type="selection" width="55"></el-table-column>
      <el-table-column label="供应商名称" align="center" min-width="150px" prop="supplierName"></el-table-column>
      <el-table-column label="供应商简介" align="center" min-width="150px" prop="supplierType"></el-table-column>
      <el-table-column label="所在地址" align="center" min-width="150px" prop="supplierLocaltion"></el-table-column>
      <el-table-column label="联系人名称" align="center" min-width="150px" prop="supplierBossName"></el-table-column>
      <el-table-column label="联系电话" align="center" min-width="150px" prop="supplierTel"></el-table-column>
      <el-table-column label="操作" align="center" width="230" class-name="small-padding fixed-width">
        <template slot-scope="{row,$index}">
          <el-button type="primary" size="mini" @click="handleSaveData(row)" icon="el-icon-edit">编辑</el-button>
          <el-button type="danger" size="mini"  @click="handleTableDelete(row)" icon="el-icon-delete">删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="param.current" :limit.sync="param.pageSize" @pagination="getList"/>
    <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible">
      <el-form ref="dataForm" :rules="rules" :model="form" label-position="left" label-width="150px" style="width: 400px; margin-left:50px;">
        <el-form-item label="供应商名称" prop="supplierName">
          <el-input v-model="form.supplierName"/>
        </el-form-item>
        <el-form-item label="供应商简介" prop="supplierType">
        <el-input type="textarea"  v-model="form.supplierType"></el-input>
        </el-form-item>
        <el-form-item label="所在地址" prop="supplierLocaltion">
        <el-input type="textarea"  v-model="form.supplierLocaltion"></el-input>
        </el-form-item>
        <el-form-item label="联系人名称" prop="supplierBossName">
          <el-input v-model="form.supplierBossName"/>
        </el-form-item>
        <el-form-item label="联系电话" prop="supplierTel">
          <el-input v-model="form.supplierTel"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取消</el-button>
        <el-button type="primary" @click="submitTableForm">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import waves from '@/directive/waves'
  import Pagination from '@/components/Pagination'
  import {tableUtil} from '../../utils/tableUtil';
  import { batchDelete, page, saveData} from '@/api/supplier/index'
  export default {
    name: 'supplier',
    components: { Pagination },
    directives: { waves },
    mixins: [tableUtil],
    data() {
      return {
        moduleUrl: '/supplier',
        param: { // 列表查询参数
          current: 1,
          pageSize: 5,
          supplierName: undefined,
        },
        form: { // 添加或修改提交表单
        id: undefined,
        supplierName: undefined,
        supplierType: undefined,
        supplierLocaltion: undefined,
        supplierBossName: undefined,
        supplierTel: undefined,
        },
        rules: { // 自定义校验规则
          supplierName: [{ required: true, message: '供应商名称为必须项~', trigger: 'blur' }],
          supplierType: [{ required: true, message: '供应商简介为必须项~', trigger: 'blur' }],
          supplierLocaltion: [{ required: true, message: '所在地址为必须项~', trigger: 'blur' }],
          supplierBossName: [{ required: true, message: '联系人名称为必须项~', trigger: 'blur' }],
          supplierTel: [{ required: true, message: '联系电话为必须项~', trigger: 'blur' }],
        },
      }
    },
    created() {
      this.getList()
    },
    methods: {
      getList() { // 表格数据分页获取
        this.listLoading = true
        page(this.param).then(res => {
          this.list = res.data.records
          this.total = res.data.total
          this.listLoading = false
        })
      },
      submitTableForm(){this.submitForm(saveData)},
      handleTableDelete(row){this.handleDelete(row,batchDelete)},
      tableHandleBatchDelete(){this.tableBatchDelete(batchDelete)},
    }
  }
</script>
